package org.fitweb;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class FitwebProperties extends Properties {

    private static FitwebProperties instance = new FitwebProperties();

    public FitwebProperties() {
        InputStream stream = getClass().getResourceAsStream("/fitweb.properties");
        if (stream != null) {
            loadFromFile(stream);
        }
    }

    private void loadFromFile(InputStream stream) {
        try {
            load(stream);
        } catch (IOException e) {
            // Couldn't find a properties file
        }
    }

    public static String property(String propertyName) {
        if (instance.size() == 0) {
            throw new IllegalStateException("No properties have been loaded. Is there a fitweb.properties file on the classpath?");
        }
        return instance.getProperty(propertyName);
    }

    public static String all() {
        return instance.toString();
    }
}
